package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.SignUp;
import cn.anxingongyou.anxin.mapper.SignUpMapper;
import cn.anxingongyou.anxin.service.SignUpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SignUpServiceImpl implements SignUpService {

    private final SignUpMapper signUpMapper;
    @Autowired
    public SignUpServiceImpl(SignUpMapper signUpMapper) {
        this.signUpMapper = signUpMapper;
    }

    @Override
    public int insert(SignUp signUp) {
        return signUpMapper.insertSelective(signUp);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return signUpMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SignUp signUp) {
        return signUpMapper.updateByPrimaryKeySelective(signUp);
    }

    @Override
    public SignUp selectOne(SignUp signUp) {
        return signUpMapper.selectOne(signUp);
    }

    @Override
    public SignUp selectOneByPrimaryKey(Long id) {
        return signUpMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<SignUp> page(int pageNum, int pageSize, SignUp signUp) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<SignUp> list = signUpMapper.select(signUp);
        PageInfo<SignUp> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int countSignUpIsEmploy(Long workId, int isEmployment) {
        SignUp signUp = new SignUp();
        signUp.setWorkId(workId);
        signUp.setIsEmployment(isEmployment);

        int count = signUpMapper.selectCount(signUp);
        return count;
    }
}
